package ejb.com.bbva.cbm.service.ejb;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;

import ejb.cbm.admin.entity.ParametroEntity;
import ejb.cbm.admin.entity.TipoParametroEntity;
import ejb.com.bbva.cbm.service.ComunServiceLocal;

/**
 * Session Bean implementation class AdministracionServiceBean
 */
@Service("comunServiceLocal")
public class ComunServiceBean  extends HibernateDaoSupport implements ComunServiceLocal {
	
    //@PersistenceContext(unitName="")
    //private EntityManager em;
	
    @Autowired
	public ComunServiceBean(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
    
    ////@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<ParametroEntity> obtenerParametrosPorTipo(Long tipoParametroId) throws Exception
    {
    	return getSession().createQuery (
    		"select o from ParametroEntity o where o.tipoparametro.codigotipoparametro = :codigotipoparametro order by o.descripcion"
    	)
    	.setParameter("codigotipoparametro", tipoParametroId)
    	.list();
    }
    ////@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<TipoParametroEntity> obtenerTiposParametrosTodos() throws Exception {
    	return getSession().createQuery (
        	"select o from TipoParametroEntity o"
        )
        .list();
    }
    public List<ParametroEntity> obtenerParametrosTodos() throws Exception {
    	return getSession().createQuery (
    		"select o from ParametroEntity o where o.parametroPadre is null"
        )
        .list();
    }
}
